﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ConsolidationTool.Common.Entities;
using System.Collections.Generic;
using ConsolidationTool.Common;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using ConsolidationTool.WebParts.ControlTemplates;

using System.ComponentModel;
using System.Data;
using System.Linq;

namespace ConsolidationTool.WebParts.Layouts.CReport.Flash
{
    public partial class TSBR : FSReportBase
    {
        public override ControlTemplates.CommonEntitySelector TopSelector
        {
            get
            {
                return commonEntitySelector as ControlTemplates.CommonEntitySelector;
            }
        }

        public override void BeforLoad()
        {
            if (!IsPostBack)
            {
                InitBaseInfo();
            }
        }
 
        void InitBaseInfo()
        {
            if (!Automatic)
            {
                TopSelector.yearTextBox.Text = Common.BusinessService.GetConfiguration(Constants.Flash_Input_Year);
                TopSelector.monthTextBox.Text = Common.BusinessService.GetConfiguration(Constants.Flash_Input_Month);
            }
            Title_HRM1.Text = TopSelector.yearTextBox.Text + ".01";
            Title_HRM2.Text = TopSelector.yearTextBox.Text + ".02";
            Title_HRM3.Text = TopSelector.yearTextBox.Text + ".03";
            Title_HRM4.Text = TopSelector.yearTextBox.Text + ".04";
            Title_HRM5.Text = TopSelector.yearTextBox.Text + ".05";
            Title_HRM6.Text = TopSelector.yearTextBox.Text + ".06";
            Title_HRM7.Text = TopSelector.yearTextBox.Text + ".07";
            Title_HRM8.Text = TopSelector.yearTextBox.Text + ".08";
            Title_HRM9.Text = TopSelector.yearTextBox.Text + ".09";
            Title_HRM10.Text = TopSelector.yearTextBox.Text + ".10";
            Title_HRM11.Text = TopSelector.yearTextBox.Text + ".11";
            Title_HRM12.Text = TopSelector.yearTextBox.Text + ".12";
        }

        public override void GenerateReport_Click(object sender, EventArgs e)
        {
            Title_HRM1.Text = TopSelector.yearTextBox.Text + ".01";
            Title_HRM2.Text = TopSelector.yearTextBox.Text + ".02";
            Title_HRM3.Text = TopSelector.yearTextBox.Text + ".03";
            Title_HRM4.Text = TopSelector.yearTextBox.Text + ".04";
            Title_HRM5.Text = TopSelector.yearTextBox.Text + ".05";
            Title_HRM6.Text = TopSelector.yearTextBox.Text + ".06";
            Title_HRM7.Text = TopSelector.yearTextBox.Text + ".07";
            Title_HRM8.Text = TopSelector.yearTextBox.Text + ".08";
            Title_HRM9.Text = TopSelector.yearTextBox.Text + ".09";
            Title_HRM10.Text = TopSelector.yearTextBox.Text + ".10";
            Title_HRM11.Text = TopSelector.yearTextBox.Text + ".11";
            Title_HRM12.Text = TopSelector.yearTextBox.Text + ".12";

            clearData();

            //邦定current月数据
            int m = Convert.ToInt32(TopSelector.monthTextBox.Text);

            
            for (int i = 1; i <= m; i++)
            {
                string strMonth = i.ToString();
                BindLastMonth(TopSelector.lbCoCd.Text, TopSelector.yearTextBox.Text, strMonth);
            }

            DataTable results = new DataTable();
            results = GetListItemsForView(TopSelector.lbCoCd.Text, TopSelector.yearTextBox.Text, TopSelector.monthTextBox.Text);
            //results.DefaultView.Sort = "Plant,ProductCode,MaterialCategory,MaterialCode ASC";
            ViewState["ReportRepeater"] = results;
            ReportRepeater.DataSource = results;
            ReportRepeater.DataBind();

            DataTable Toresults = new DataTable();
            Toresults = GetTOListItemsForView(TopSelector.lbCoCd.Text, TopSelector.yearTextBox.Text, TopSelector.monthTextBox.Text);
            //results.DefaultView.Sort = "Plant,ProductCode,MaterialCategory,MaterialCode ASC";
            ViewState["TOReportRepeater"] = Toresults;
            TOReportRepeater.DataSource = Toresults;
            TOReportRepeater.DataBind(); 
            
        }

        private DataTable GetListItemsForView(string coCd, string year, string month)
        {

            DataTable resultList = new DataTable();
            resultList.Columns.Add("RGC");
            resultList.Columns.Add("Description");
            resultList.Columns.Add("QTY01");
            resultList.Columns.Add("QTY02");
            resultList.Columns.Add("QTY03");
            resultList.Columns.Add("QTY04");
            resultList.Columns.Add("QTY05");
            resultList.Columns.Add("QTY06");
            resultList.Columns.Add("QTY07");
            resultList.Columns.Add("QTY08");
            resultList.Columns.Add("QTY09");
            resultList.Columns.Add("QTY10");
            resultList.Columns.Add("QTY11");
            resultList.Columns.Add("QTY12");
            resultList.Columns.Add("QTY13");
            resultList.Columns.Add("QTY14");
            resultList.Columns.Add("QTY15");
            resultList.Columns.Add("QTY16");
            resultList.Columns.Add("QTY17");
            resultList.Columns.Add("QTY18");
            resultList.Columns.Add("QTY19");
            resultList.Columns.Add("QTY20");
            resultList.Columns.Add("QTY21");
            resultList.Columns.Add("QTY22");
            resultList.Columns.Add("QTY23");
            resultList.Columns.Add("QTY24");

            int m = Convert.ToInt32(TopSelector.monthTextBox.Text);

            for (int i = 1; i <= m; i++)
            {
                string mo = Convert.ToString(i);
                SPListItemCollection items = Common.BusinessService.GetSubItems(coCd, year, mo, "Sub Trade Sales By RGC", "SV01020100");

                if (items != null)
                {
                    for (int j = 1; j <= items.Count; j++)
                    {
                        if (resultList.Rows.Count > 0)
                        {
                            int n = 0;
                            for (int k = 1; k <= resultList.Rows.Count; k++)
                            {
                                if (items[j - 1]["RGC"].ToString() == resultList.Rows[k-1]["RGC"].ToString())
                                {
                                    n = k;
                                }
                            }
                            if (n != 0)
                            {
                                switch (mo)
                                {
                                    case "1":
                                        resultList.Rows[n-1]["QTY01"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY02"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "2":
                                        resultList.Rows[n-1]["QTY03"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY04"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "3":
                                        resultList.Rows[n-1]["QTY05"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY06"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "4":
                                        resultList.Rows[n-1]["QTY07"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY08"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "5":
                                        resultList.Rows[n-1]["QTY09"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY10"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "6":
                                        resultList.Rows[n-1]["QTY11"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY12"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "7":
                                        resultList.Rows[n-1]["QTY13"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY14"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "8":
                                        resultList.Rows[n-1]["QTY15"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY16"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "9":
                                        resultList.Rows[n-1]["QTY17"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY18"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "10":
                                        resultList.Rows[n-1]["QTY19"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY20"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "11":
                                        resultList.Rows[n-1]["QTY21"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY22"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "12":
                                        resultList.Rows[n-1]["QTY23"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        resultList.Rows[n-1]["QTY24"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;

                                    default:
                                        break;
                                }

                                resultList.AcceptChanges();
                            }
                            else
                            {
                                DataRow report = resultList.NewRow();
                                report["RGC"] = items[j - 1]["RGC"].ToString();
                                report["Description"] = Common.BusinessService.GetRGCDescriptionByRGC(items[j - 1]["RGC"].ToString());
                                switch (mo)
                                {
                                    case "1":
                                        report["QTY01"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY02"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "2":
                                        report["QTY03"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY04"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "3":
                                        report["QTY05"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY06"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "4":
                                        report["QTY07"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY08"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "5":
                                        report["QTY09"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY10"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "6":
                                        report["QTY11"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY12"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "7":
                                        report["QTY13"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY14"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "8":
                                        report["QTY15"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY16"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "9":
                                        report["QTY17"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY18"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "10":
                                        report["QTY19"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY20"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "11":
                                        report["QTY21"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY22"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    case "12":
                                        report["QTY23"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                        report["QTY24"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                        break;
                                    default:
                                        break;
                                }

                                resultList.Rows.Add(report);
                                resultList.AcceptChanges();
                            }
                        }
                        else
                        {
                            DataRow report = resultList.NewRow();
                            report["RGC"] = items[j - 1]["RGC"].ToString();
                            report["Description"] = Common.BusinessService.GetRGCDescriptionByRGC(items[j - 1]["RGC"].ToString());
                            switch (mo)
                            {
                                case "1":
                                    report["QTY01"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY02"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "2":
                                    report["QTY03"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY04"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "3":
                                    report["QTY05"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY06"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "4":
                                    report["QTY07"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY08"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "5":
                                    report["QTY09"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY10"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "6":
                                    report["QTY11"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY12"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "7":
                                    report["QTY13"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY14"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "8":
                                    report["QTY15"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY16"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "9":
                                    report["QTY17"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY18"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "10":
                                    report["QTY19"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY20"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "11":
                                    report["QTY21"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY22"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                case "12":
                                    report["QTY23"] = items[j - 1]["CM_QTY_SV01020100"].ToString();
                                    report["QTY24"] = items[j - 1]["CM_T_SV01020100"].ToString();
                                    break;
                                default:
                                    break;
                            }
                            

                            resultList.Rows.Add(report);
                            resultList.AcceptChanges();
                        }
                    }
                }
            } 

            return resultList;
        }

        private DataTable GetTOListItemsForView(string coCd, string year, string month)
        {

            DataTable resultList = new DataTable();
            resultList.Columns.Add("TORGC");
            resultList.Columns.Add("TODescription");
            resultList.Columns.Add("TOQTY01");
            resultList.Columns.Add("TOQTY02");
            resultList.Columns.Add("TOQTY03");
            resultList.Columns.Add("TOQTY04");
            resultList.Columns.Add("TOQTY05");
            resultList.Columns.Add("TOQTY06");
            resultList.Columns.Add("TOQTY07");
            resultList.Columns.Add("TOQTY08");
            resultList.Columns.Add("TOQTY09");
            resultList.Columns.Add("TOQTY10");
            resultList.Columns.Add("TOQTY11");
            resultList.Columns.Add("TOQTY12");
            resultList.Columns.Add("TOQTY13");
            resultList.Columns.Add("TOQTY14");
            resultList.Columns.Add("TOQTY15");
            resultList.Columns.Add("TOQTY16");
            resultList.Columns.Add("TOQTY17");
            resultList.Columns.Add("TOQTY18");
            resultList.Columns.Add("TOQTY19");
            resultList.Columns.Add("TOQTY20");
            resultList.Columns.Add("TOQTY21");
            resultList.Columns.Add("TOQTY22");
            resultList.Columns.Add("TOQTY23");
            resultList.Columns.Add("TOQTY24");

            int m = Convert.ToInt32(TopSelector.monthTextBox.Text);

            for (int i = 1; i <= m; i++)
            {
                string mo = Convert.ToString(i);
                SPListItemCollection items = Common.BusinessService.GetSubItems(coCd, year, mo, "Sub Trade Sales By RGC", "SV01020200");

                if (items != null)
                {
                    for (int j = 1; j <= items.Count; j++)
                    {
                        if (resultList.Rows.Count > 0)
                        {
                            int n = 0;
                            for (int k = 1; k <= resultList.Rows.Count; k++)
                            {
                                if (items[j - 1]["RGC"].ToString() == resultList.Rows[k - 1]["TORGC"].ToString())
                                {
                                    n = k;
                                }
                            }
                            if (n != 0)
                            {
                                switch (mo)
                                {
                                    case "1":
                                        resultList.Rows[n - 1]["TOQTY01"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY02"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "2":
                                        resultList.Rows[n - 1]["TOQTY03"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY04"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "3":
                                        resultList.Rows[n - 1]["TOQTY05"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY06"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "4":
                                        resultList.Rows[n - 1]["TOQTY07"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY08"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "5":
                                        resultList.Rows[n - 1]["TOQTY09"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY10"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "6":
                                        resultList.Rows[n - 1]["TOQTY11"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY12"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "7":
                                        resultList.Rows[n - 1]["TOQTY13"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY14"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "8":
                                        resultList.Rows[n - 1]["TOQTY15"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY16"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "9":
                                        resultList.Rows[n - 1]["TOQTY17"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY18"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "10":
                                        resultList.Rows[n - 1]["TOQTY19"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY20"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "11":
                                        resultList.Rows[n - 1]["TOQTY21"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY22"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "12":
                                        resultList.Rows[n - 1]["TOQTY23"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        resultList.Rows[n - 1]["TOQTY24"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;

                                    default:
                                        break;
                                }

                                resultList.AcceptChanges();
                            }
                            else
                            {
                                DataRow report = resultList.NewRow();
                                report["TORGC"] = items[j - 1]["RGC"].ToString();
                                report["TODescription"] = Common.BusinessService.GetRGCDescriptionByRGC(items[j - 1]["RGC"].ToString());
                                switch (mo)
                                {
                                    case "1":
                                        report["TOQTY01"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY02"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "2":
                                        report["TOQTY03"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY04"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "3":
                                        report["TOQTY05"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY06"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "4":
                                        report["TOQTY07"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY08"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "5":
                                        report["TOQTY09"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY10"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "6":
                                        report["TOQTY11"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY12"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "7":
                                        report["TOQTY13"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY14"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "8":
                                        report["TOQTY15"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY16"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "9":
                                        report["TOQTY17"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY18"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "10":
                                        report["TOQTY19"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY20"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "11":
                                        report["TOQTY21"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY22"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    case "12":
                                        report["TOQTY23"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                        report["TOQTY24"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                        break;
                                    default:
                                        break;
                                }

                                resultList.Rows.Add(report);
                                resultList.AcceptChanges();
                            }
                        }
                        else
                        {
                            DataRow report = resultList.NewRow();
                            report["TORGC"] = items[j - 1]["RGC"].ToString();
                            report["TODescription"] = Common.BusinessService.GetRGCDescriptionByRGC(items[j - 1]["RGC"].ToString());
                            switch (mo)
                            {
                                case "1":
                                    report["TOQTY01"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY02"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "2":
                                    report["TOQTY03"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY04"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "3":
                                    report["TOQTY05"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY06"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "4":
                                    report["TOQTY07"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY08"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "5":
                                    report["TOQTY09"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY10"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "6":
                                    report["TOQTY11"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY12"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "7":
                                    report["TOQTY13"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY14"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "8":
                                    report["TOQTY15"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY16"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "9":
                                    report["TOQTY17"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY18"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "10":
                                    report["TOQTY19"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY20"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "11":
                                    report["TOQTY21"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY22"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                case "12":
                                    report["TOQTY23"] = items[j - 1]["CM_QTY_SV01020200"].ToString();
                                    report["TOQTY24"] = items[j - 1]["CM_T_SV01020200"].ToString();
                                    break;
                                default:
                                    break;
                            }


                            resultList.Rows.Add(report);
                            resultList.AcceptChanges();
                        }
                    }
                }
            }

            return resultList;
        }

        void BindLastMonth(string coCd, string year, string month)
        {
            string y = year;
            string m = (Convert.ToInt32(month)).ToString();
            SPListItem it = Common.BusinessService.GetItem(coCd, y, m, "Trade Sales By RGC");
            
            if (it != null)
            {
                switch (m)
                {
                    case "1":
                        Label_HRR01_C01.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C01.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C01.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C02.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C02.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C02.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");

                        break;
                    case "2":
                        Label_HRR01_C03.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C03.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C03.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C04.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C04.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C04.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "3":
                        Label_HRR01_C05.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C05.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C05.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C06.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C06.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C06.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "4":
                        Label_HRR01_C07.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C07.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C07.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C08.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C08.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C08.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "5":
                        Label_HRR01_C09.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C09.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C09.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C10.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C10.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C10.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "6":
                        Label_HRR01_C11.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C11.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C11.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C12.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C12.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C12.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "7":
                        Label_HRR01_C13.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C13.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C13.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C14.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C14.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C14.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "8":
                        Label_HRR01_C15.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C15.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C15.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C16.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C16.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C16.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "9":
                        Label_HRR01_C17.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C17.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C17.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C18.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C18.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C18.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "10":
                        Label_HRR01_C19.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C19.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C19.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C20.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C20.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C20.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "11":
                        Label_HRR01_C21.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C21.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C21.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C22.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C22.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C22.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    case "12":
                        Label_HRR01_C23.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020100");
                        Label_HRR02_C23.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020200");
                        Label_HRR03_C23.Text = Common.Utilities.GetItemValue(it, "CM_QTY_SV01020300");
                        Label_HRR01_C24.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020100");
                        Label_HRR02_C24.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020200");
                        Label_HRR03_C24.Text = Common.Utilities.GetItemValue(it, "CM_T_SV01020300");
                        break;
                    default:
                        break;
                }
            }
        }

        void clearData()
        {
            Label_HRR01_C01.Text = "";
            Label_HRR02_C01.Text = "";
            Label_HRR03_C01.Text = "";
            Label_HRR01_C02.Text = "";
            Label_HRR02_C02.Text = "";
            Label_HRR03_C02.Text = "";
            Label_HRR01_C03.Text = "";
            Label_HRR02_C03.Text = "";
            Label_HRR03_C03.Text = "";
            Label_HRR01_C04.Text = "";
            Label_HRR02_C04.Text = "";
            Label_HRR03_C04.Text = "";
            Label_HRR01_C05.Text = "";
            Label_HRR02_C05.Text = "";
            Label_HRR03_C05.Text = "";
            Label_HRR01_C06.Text = "";
            Label_HRR02_C06.Text = "";
            Label_HRR03_C06.Text = "";
            Label_HRR01_C07.Text = "";
            Label_HRR02_C07.Text = "";
            Label_HRR03_C07.Text = "";
            Label_HRR01_C08.Text = "";
            Label_HRR02_C08.Text = "";
            Label_HRR03_C08.Text = "";
            Label_HRR01_C09.Text = "";
            Label_HRR02_C09.Text = "";
            Label_HRR03_C09.Text = "";
            Label_HRR01_C10.Text = "";
            Label_HRR02_C10.Text = "";
            Label_HRR03_C10.Text = "";
            Label_HRR01_C11.Text = "";
            Label_HRR02_C11.Text = "";
            Label_HRR03_C11.Text = "";
            Label_HRR01_C12.Text = "";
            Label_HRR02_C12.Text = "";
            Label_HRR03_C12.Text = "";
            Label_HRR01_C13.Text = "";
            Label_HRR02_C13.Text = "";
            Label_HRR03_C13.Text = "";
            Label_HRR01_C14.Text = "";
            Label_HRR02_C14.Text = "";
            Label_HRR03_C14.Text = "";
            Label_HRR01_C15.Text = "";
            Label_HRR02_C15.Text = "";
            Label_HRR03_C15.Text = "";
            Label_HRR01_C16.Text = "";
            Label_HRR02_C16.Text = "";
            Label_HRR03_C16.Text = "";
            Label_HRR01_C17.Text = "";
            Label_HRR02_C17.Text = "";
            Label_HRR03_C17.Text = "";
            Label_HRR01_C18.Text = "";
            Label_HRR02_C18.Text = "";
            Label_HRR03_C18.Text = "";
            Label_HRR01_C19.Text = "";
            Label_HRR02_C19.Text = "";
            Label_HRR03_C19.Text = "";
            Label_HRR01_C20.Text = "";
            Label_HRR02_C20.Text = "";
            Label_HRR03_C20.Text = "";
            Label_HRR01_C21.Text = "";
            Label_HRR02_C21.Text = "";
            Label_HRR03_C21.Text = "";
            Label_HRR01_C22.Text = "";
            Label_HRR02_C22.Text = "";
            Label_HRR03_C22.Text = "";
            Label_HRR01_C23.Text = "";
            Label_HRR02_C23.Text = "";
            Label_HRR03_C23.Text = "";
            Label_HRR01_C24.Text = "";
            Label_HRR02_C24.Text = "";
            Label_HRR03_C24.Text = "";
        }
    }
}
